home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / domacnost a kancelar / joomla / Joomla_1.5.4-Stable-Full_Package.exe / plugins / system / debug.php < prev    next >
PHP Script  |  2008-07-06  |  6KB  |  208 lines

  1. <?php
  2. /**
  3. * @version        $Id: debug.php 10457 2008-06-27 05:52:12Z eddieajau $
  4. * @package        Joomla
  5. * @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  6. * @license        GNU/GPL, see LICENSE.php
  7. * Joomla! is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYRIGHT.php for copyright notices and details.
  12. */
  13.  
  14. // no direct access
  15. defined( '_JEXEC' ) or die( 'Restricted access' );
  16.  
  17. jimport( 'joomla.plugin.plugin' );
  18.  
  19. /**
  20.  * Joomla! Debug plugin
  21.  *
  22.  * @author        Johan Janssens <johan.janssens@joomla.org>
  23.  * @package        Joomla
  24.  * @subpackage    System
  25.  */
  26. class  plgSystemDebug extends JPlugin
  27. {
  28.     /**
  29.      * Constructor
  30.      *
  31.      * For php4 compatability we must not use the __constructor as a constructor for plugins
  32.      * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
  33.      * This causes problems with cross-referencing necessary for the observer design pattern.
  34.      *
  35.      * @access    protected
  36.      * @param    object $subject The object to observe
  37.      * @param     array  $config  An array that holds the plugin configuration
  38.      * @since    1.0
  39.      */
  40.     function plgSystemDebug(& $subject, $config)
  41.     {
  42.         parent::__construct($subject, $config);
  43.  
  44.         //load the translation
  45.         $this->loadLanguage( );
  46.     }
  47.  
  48.     /**
  49.     * Converting the site URL to fit to the HTTP request
  50.     *
  51.     */
  52.     function onAfterRender()
  53.     {
  54.         global $_PROFILER, $mainframe, $database;
  55.  
  56.         // Do not render if debugging is not enabled
  57.         if(!JDEBUG) { return; }
  58.  
  59.         $document    =& JFactory::getDocument();
  60.         $doctype    = $document->getType();
  61.  
  62.         // Only render for HTML output
  63.         if ( $doctype !== 'html' ) { return; }
  64.  
  65.         $profiler    =& $_PROFILER;
  66.  
  67.         ob_start();
  68.         echo '<div id="system-debug" class="profiler">';
  69.         if ($this->params->get('profile', 1)) {
  70.             echo '<h4>'.JText::_( 'Profile Information' ).'</h4>';
  71.             foreach ( $profiler->getBuffer() as $mark ) {
  72.                 echo '<div>'.$mark.'</div>';
  73.             }
  74.         }
  75.  
  76.         if ($this->params->get('memory', 1)) {
  77.             echo '<h4>'.JText::_( 'Memory Usage' ).'</h4>';
  78.             echo $profiler->getMemory();
  79.         }
  80.  
  81.         if ($this->params->get('queries', 1))
  82.         {
  83.             jimport('geshi.geshi');
  84.  
  85.             $geshi = new GeSHi( '', 'sql' );
  86.             $geshi->set_header_type(GESHI_HEADER_DIV);
  87.             //$geshi->enable_line_numbers( GESHI_FANCY_LINE_NONE );
  88.  
  89.             $newlineKeywords = '/<span style="color: #993333; font-weight: bold;">'
  90.                 .'(FROM|LEFT|INNER|OUTER|WHERE|SET|VALUES|ORDER|GROUP|HAVING|LIMIT|ON|AND)'
  91.                 .'<\\/span>/i'
  92.             ;
  93.  
  94.             $db    =& JFactory::getDBO();
  95.  
  96.             echo '<h4>'.JText::sprintf( 'Queries logged',  $db->getTicker() ).'</h4>';
  97.  
  98.             if ($log = $db->getLog())
  99.             {
  100.                 echo '<ol>';
  101.                 foreach ($log as $k=>$sql)
  102.                 {
  103.                     $geshi->set_source($sql);
  104.                     $text = $geshi->parse_code();
  105.                     $text = preg_replace($newlineKeywords, '<br />  \\0', $text);
  106.                     echo '<li>'.$text.'</li>';
  107.                 }
  108.                 echo '</ol>';
  109.             }
  110.  
  111.             if(isset($database))
  112.             {
  113.                 echo '<h4>'.JText::sprintf( 'Legacy Queries logged',  $database->getTicker() ).'</h4>';
  114.                 echo '<ol>';
  115.  
  116.                     foreach ($database->getLog() as $k=>$sql)
  117.                     {
  118.                         $geshi->set_source($sql);
  119.                         $text = $geshi->parse_code();
  120.                         $text = preg_replace($newlineKeywords, '<br />  \\0', $text);
  121.                         echo '<li>'.$text.'</li>';
  122.                     }
  123.  
  124.                 echo '</ol>';
  125.             }
  126.         }
  127.  
  128.         $lang = &JFactory::getLanguage();
  129.         if ($this->params->get('language_files', 1))
  130.         {
  131.             echo '<h4>'.JText::_( 'Language Files Loaded' ).'</h4>';
  132.             echo '<ul>';
  133.             $extensions    = $lang->getPaths();
  134.             foreach ( $extensions as $extension => $files)
  135.             {
  136.                 foreach ( $files as $file => $status )
  137.                 {
  138.                     echo "<li>$file $status</li>";
  139.                 }
  140.             }
  141.             echo '</ul>';
  142.         }
  143.  
  144.         $langStrings = $this->params->get('language_strings', -1);
  145.         if ($langStrings < 0 OR $langStrings == 1) {
  146.             echo '<h4>'.JText::_( 'Untranslated Strings Diagnostic' ).'</h4>';
  147.             echo '<pre>';
  148.             $orphans = $lang->getOrphans();
  149.             if (count( $orphans ))
  150.             {
  151.                 ksort( $orphans, SORT_STRING );
  152.                 foreach ($orphans as $key => $occurance) {
  153.                     foreach ( $occurance as $i => $info) {
  154.                         $class    = @$info['class'];
  155.                         $func    = @$info['function'];
  156.                         $file    = @$info['file'];
  157.                         $line    = @$info['line'];
  158.                         echo strtoupper( $key )."\t$class::$func()\t[$file:$line]\n";
  159.                     }
  160.                 }
  161.             }
  162.             else {
  163.                 echo JText::_( 'None' );
  164.             }
  165.             echo '</pre>';
  166.         }
  167.         if ($langStrings < 0 OR $langStrings == 2) {
  168.             echo '<h4>'.JText::_( 'Untranslated Strings Designer' ).'</h4>';
  169.             echo '<pre>';
  170.             $orphans = $lang->getOrphans();
  171.             if (count( $orphans ))
  172.             {
  173.                 ksort( $orphans, SORT_STRING );
  174.                 $guesses = array();
  175.                 foreach ($orphans as $key => $occurance) {
  176.                     if (is_array( $occurance ) AND isset( $occurance[0] )) {
  177.                         $info = &$occurance[0];
  178.                         $file = @$info['file'];
  179.                         if (!isset( $guesses[$file] )) {
  180.                             $guesses[$file] = array();
  181.                         }
  182.  
  183.                         $guess = str_replace( '_', ' ', $info['string'] );
  184.                         if ($strip = $this->params->get('language_prefix')) {
  185.                             $guess = trim( preg_replace( chr(1).'^'.$strip.chr(1), '', $guess ) );
  186.                         }
  187.                         $guesses[$file][] = trim( strtoupper( $key ) ).'='.$guess;
  188.                     }
  189.                 }
  190.                 foreach ($guesses as $file => $keys) {
  191.                     echo "\n\n# ".($file ? $file : JText::_( 'Unknown file' ))."\n\n";
  192.                     echo implode( "\n", $keys );
  193.                 }
  194.             }
  195.             else {
  196.                 echo JText::_( 'None' );
  197.             }
  198.             echo '</pre>';
  199.         }
  200.         echo '</div>';
  201.  
  202.         $debug = ob_get_clean();
  203.  
  204.         $body = JResponse::getBody();
  205.         $body = str_replace('</body>', $debug.'</body>', $body);
  206.         JResponse::setBody($body);
  207.     }
  208. }